What is void-elements?
The void-elements npm package provides a list of HTML void elements. Void elements are HTML elements that do not have closing tags, such as <img>, <br>, and <input>. This package is useful for developers who need to handle or validate HTML content programmatically.
What are void-elements's main functionalities?
List of Void Elements
This feature provides a list of all HTML void elements. The code sample demonstrates how to import the package and log the list of void elements to the console.
const voidElements = require('void-elements');
console.log(voidElements);
Check if an Element is Void
This feature allows you to check if a given HTML tag is a void element. The code sample shows how to create a function that checks if a tag name is in the list of void elements and demonstrates its usage with 'img' and 'div' tags.
const voidElements = require('void-elements');
const isVoidElement = (tagName) => voidElements.includes(tagName);
console.log(isVoidElement('img')); // true
console.log(isVoidElement('div')); // false
Other packages similar to void-elements
html-tags
The html-tags package provides a list of all standard HTML tags, including both void and non-void elements. It is more comprehensive than void-elements as it covers all HTML tags, not just void elements.
self-closing-tags
The self-closing-tags package offers a list of self-closing HTML tags, which is similar to void elements. However, it focuses on tags that can self-close in XML and XHTML contexts, which may include more than just the standard HTML void elements.
void-elements
Array of "void elements" defined by the HTML specification
Exports an Array of "void element" node names as defined by the HTML spec.
The list is programatically generated from SPEC.
Usage
var voidElements = require('void-elements');
assert(voidElements.indexOf('span') === -1, '<span> is not a void element');
assert(voidElements.indexOf('img') !== -1, '<img> is a void element');
License
MIT